package com.kiln.juxingqs.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.global.commlib.network.data.JsonResult
import client.global.commlib.network.data.Ret
import client.global.commlib.toast.toast
import com.kiln.juxingqs.api.bean.GetDddBatchRet
import com.kiln.juxingqs.api.bean.TradeGoodsDetail
import com.kiln.juxingqs.api.bean.Zcjl
import com.kiln.juxingqs.ui.viewmodel.MiddleVm

class ZrLotsViewModel(app: Application) : MiddleVm(app) {
    val isShowing = MutableLiveData<Boolean>(false)

    val isOneLoading = MutableLiveData<Boolean>(false)
    val pageOne = MutableLiveData<Int>(0)
    var goods_name = MutableLiveData<String>("")
    var deal_num = MutableLiveData<String>("")

    val callOne = MutableLiveData<JsonResult<GetDddBatchRet>>()
    val retOne = MutableLiveData<JsonResult<Zcjl>>()
    val queRenRet = MutableLiveData<JsonResult<Ret>>()
    val buyRet = MutableLiveData<JsonResult<Ret>>()
    val zzRet = MutableLiveData<JsonResult<Ret>>()


    fun jYzcjl(goods_id: String, r_label: Int) {
        if (isOneLoading.value!!)
            return
        hold({
            server.jYzcjl(goods_id, pageOne.value!!, r_label, "", "")
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            retOne.value = it
        }, complete = {
            isOneLoading.value = false
        })

    }

    fun holdOne(goods_id: String?, r_type: String?) {
        if (isOneLoading.value!!)
            return
        hold({
            server.batch_record_v2(r_type!!, goods_id!!, pageOne.value!!)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callOne.value = it
        }, complete = {
            isOneLoading.value = false
        })

    }


    fun holdSellBatchTrade(goods_id: String?) {
        if (isOneLoading.value!!)
            return
        hold({
            server.sell_batch_trade(goods_id!!, pageOne.value!!)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callOne.value = it
        }, complete = {
            isOneLoading.value = false
        })

    }


    fun saveTo() {
        toast("转存")
    }


    fun oneTouchRedeposit(goods_id: String) {
        hold({
            server.one_touch_redeposit(
                goods_id
            )
        }, {
            isShowing.value = true
        }, {
            queRenRet.value = it
        }, complete = {
            isShowing.value = false

        })
    }


    fun holdBuyTj(goods_id: String, price_pf: String, num: String) {
        hold({
            server.trade_goods_buy_tj(goods_id, price_pf, num)

        }, {
            isShowing.value = true
        }, success = {
            buyRet.value = it
        }, complete = {
            isShowing.value = false

        })
    }

    fun holdZz(num: String, goods_id: String?) {
        hold({
            server.transfer_take_num(num, goods_id)
        }, {
            isShowing.value = true
        }, success = {
            zzRet.value = it
        }, complete = {
            isShowing.value = false

        })
    }

}